﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Security.Cryptography;
using System.Threading;
using System.Xml;

namespace MDD.PML.Utility
{
    internal class OperationLibrary
    {
        private ArgsParser argsParser;
        private ArgsValidator argsVal;

        internal OperationLibrary(ArgsParser argsParser)
        {
            this.argsParser = argsParser;
            argsVal = new ArgsValidator();
        }

        internal void PIM2PSM()
        {
            string filePath = argsParser[Arguments.filename.ToString()];
            if (!Path.IsPathRooted(filePath))
                filePath = Path.Combine(Directory.GetCurrentDirectory(), filePath);

            ModelType modelType;
            if (!string.IsNullOrEmpty(argsParser[Arguments.modeltype.ToString()]))
            {
                switch (argsParser[Arguments.modeltype.ToString()].ToLower())
                {
                    case "all":
                        modelType = ModelType.all;
                        break;

                    case "upml":
                        modelType = ModelType.upml;
                        break;

                    case "spml":
                        modelType = ModelType.spml;
                        break;

                    default:
                        modelType = ModelType.all;
                        break;
                }
            }
            else 
            {
                modelType = ModelType.all;
            }

            MDD.PML.Utility.PIM2PSM.Transform(filePath, modelType);
        }

        internal void PSM2Umbraco()
        {
            string filePath = argsParser[Arguments.filename.ToString()];
            if (!Path.IsPathRooted(filePath))
                filePath = Path.Combine(Directory.GetCurrentDirectory(), filePath);

            MDD.PML.Utility.PSM2T.Transform(filePath);
        }

        internal void Umbraco2PSM()
        {
            string filePath = argsParser[Arguments.filename.ToString()];
            if (!Path.IsPathRooted(filePath))
                filePath = Path.Combine(Directory.GetCurrentDirectory(), filePath);
            
            MDD.PML.Utility.T2PSM.Transform(filePath);
        }

        internal void PSM2PIM()
        {
            string filePath = argsParser[Arguments.filename.ToString()];
            if (!Path.IsPathRooted(filePath))
                filePath = Path.Combine(Directory.GetCurrentDirectory(), filePath);

            MDD.PML.Utility.PSM2PIM.Transform(filePath);
        }
    }
}
